package br.urca.impl;

import javax.inject.Inject;
import javax.persistence.EntityManager;

import br.urca.dao.PeriodoDAO;
import br.urca.model.Periodo;

public class JPAPeriodoDAO implements PeriodoDAO {

	private final EntityManager manager;

	public JPAPeriodoDAO() {
		this(null);
	}

	@Inject
	public JPAPeriodoDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public Periodo getPeriodoPadrao() {
		try {
			return this.manager
					.createQuery(
							"SELECT p FROM Periodo p "
									+ "WHERE p.situacao = :situacao ",
							Periodo.class).setParameter("situacao", "A")
					.getSingleResult();
		} catch (Exception e) {
			return null;
		}
	}

}
